package com.pentalog.ginet;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.pentalog.ginet.domain.Employee;
import com.pentalog.util.HibernateUtil;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	System.out.println("Hibernate one to one (Annotation)");
    	SessionFactory factory = HibernateUtil.getSessionFactoryAnnotation();
 
		Session session1 = factory.openSession();
        Object o=session1.load(Employee.class,new Integer(2));
 
        Employee s=(Employee)o;
        System.out.println("Loaded object product name is___"+s.getFirstName());
        System.out.println("Object Loaded successfully.....!!");
        session1.close();
 
        System.out.println("------------------------------");
        System.out.println("Waiting......");
 
        try{
            Thread.sleep(6000);
        }
        catch (Exception e) {
        }       
 
        System.out.println("6 seconds compelted......!!!!!!!!");
 
        Session session2 = factory.openSession();
        Object o2=session2.load(Employee.class,new Integer(2));
 
        Employee s2=(Employee)o2;
        System.out.println("Loaded object product name is___"+s2.getFirstName());
        System.out.println("Object loaded from the database...!!");
        session2.close();
 
        Session session3 = factory.openSession();
        Object o3=session3.load(Employee.class,new Integer(2));
 
        Employee s3=(Employee)o3;
        System.out.println("Loaded object product name is___"+s3.getFirstName());
        System.out.println("Object loaded from global cache successfully.....!!");
        session3.close();
    }
}
